package com.ruoyi.project.wechatprogram.moneyoperatelog.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.wechatprogram.moneyoperatelog.domain.WxMoneyOperateLog;
import com.ruoyi.project.wechatprogram.moneyoperatelog.service.IWxMoneyOperateLogService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 员工金额变动记录Controller
 * 
 * @author xinchen
 * @date 2020-05-21
 */
@Controller
@RequestMapping("/wechatprogram/moneyOperateLog")
public class WxMoneyOperateLogController extends BaseController
{
    private String prefix = "wechatprogram/moneyOperateLog";
    private Integer moneyOperateLogType = 0;

    @Autowired
    private IWxMoneyOperateLogService wxMoneyOperateLogService;

    @RequiresPermissions("wechatprogram:moneyOperateLog:view")
    @GetMapping()
    public String moneyOperateLog()
    {
        return prefix + "/moneyOperateLog";
    }

    /**
     * 查询员工金额变动记录列表
     */
    @RequiresPermissions("wechatprogram:moneyOperateLog:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WxMoneyOperateLog wxMoneyOperateLog)
    {
        startPage();
        List<WxMoneyOperateLog> list = wxMoneyOperateLogService.selectWxMoneyOperateLogList(wxMoneyOperateLog);
        for (WxMoneyOperateLog moneyOperateLog:list) {
            Integer change = moneyOperateLog.getBalanceChange();
            Integer type = moneyOperateLog.getType();
            if(type == moneyOperateLogType){
                moneyOperateLog.setChange("+" + change);
            }else {
                moneyOperateLog.setChange("-" + change);
            }
        }
        return getDataTable(list);
    }

    /**
     * 查询员工金额变动记录列表
     */
    @PostMapping("/wxlist")
    @ResponseBody
    public TableDataInfo wxlist(String phone)
    {
        startPage();
        List<WxMoneyOperateLog> list = wxMoneyOperateLogService.selectWxMoneyOperateLogListByPhone(phone);
        return getDataTable(list);
    }

    /**
     * 导出员工金额变动记录列表
     */
    @RequiresPermissions("wechatprogram:moneyOperateLog:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WxMoneyOperateLog wxMoneyOperateLog)
    {
        List<WxMoneyOperateLog> list = wxMoneyOperateLogService.selectWxMoneyOperateLogList(wxMoneyOperateLog);
        ExcelUtil<WxMoneyOperateLog> util = new ExcelUtil<WxMoneyOperateLog>(WxMoneyOperateLog.class);
        return util.exportExcel(list, "moneyOperateLog");
    }

    /**
     * 新增员工金额变动记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存员工金额变动记录
     */
    @RequiresPermissions("wechatprogram:moneyOperateLog:add")
    @Log(title = "员工金额变动记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WxMoneyOperateLog wxMoneyOperateLog)
    {
        return toAjax(wxMoneyOperateLogService.insertWxMoneyOperateLog(wxMoneyOperateLog));
    }

    /**
     * 修改员工金额变动记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        WxMoneyOperateLog wxMoneyOperateLog = wxMoneyOperateLogService.selectWxMoneyOperateLogById(id);
        mmap.put("wxMoneyOperateLog", wxMoneyOperateLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存员工金额变动记录
     */
    @RequiresPermissions("wechatprogram:moneyOperateLog:edit")
    @Log(title = "员工金额变动记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WxMoneyOperateLog wxMoneyOperateLog)
    {
        return toAjax(wxMoneyOperateLogService.updateWxMoneyOperateLog(wxMoneyOperateLog));
    }

    /**
     * 删除员工金额变动记录
     */
    @RequiresPermissions("wechatprogram:moneyOperateLog:remove")
    @Log(title = "员工金额变动记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wxMoneyOperateLogService.deleteWxMoneyOperateLogByIds(ids));
    }
}
